import request from '@/utils/request'
import { TradeMarkResponseData, TradeMark } from './type'

enum API {
  //获取已有品牌接口
  TRADEMARK_URL = '/admin/product/baseTrademark/',
  //添加品牌
  ADDTRADEMARK_URL = '/admin/product/baseTrademark/save',
  //修改已有品牌
  UPDATETRADEMARK_URL = '/admin/product/baseTrademark/update',
  //删除已有品牌
  DELETE_URL = '/admin/product/baseTrademark/remove/',
}

//第一种方式分页查询
// export const reqHasTrademark = (page: number, limit: number) => request.get<any, TradeMarkResponseData>(API.TRADEMARK_URL + `${page}/${limit}`);

class TrademarkApi {
  //分页查询接口
  public static reqHasTrademark(
    pageNo: number,
    limit: number,
  ): Promise<TradeMarkResponseData> {
    return request.get<any, TradeMarkResponseData>(
      API.TRADEMARK_URL + `${pageNo}/${limit}`,
    )
  }

  //添加与修改已有品牌接口方法
  public static reqAddOrUpdateTrademark(data: TradeMark) {
    //修改已有品牌的数据
    if (data.id) {
      return request.put<any, any>(API.UPDATETRADEMARK_URL, data)
    } else {
      return request.post<any, any>(API.ADDTRADEMARK_URL, data)
    }
  }

  //删除
  public static reqDeleteTrademark(id: number) {
    return request.delete<any, any>(API.DELETE_URL + id)
  }
}

export default TrademarkApi
